package main

import (
	"os"

	"gitee.com/zoneaurora/shop/internal/common"
	"gitee.com/zoneaurora/shop/internal/handler"

	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
)

func init() {
	workDir, err := os.Getwd()
	if err != nil {
		panic("工作路径获取失败")
	}
	viper.SetConfigName("config")
	viper.SetConfigType("yml")
	viper.AddConfigPath(workDir + "/config")
	err = viper.ReadInConfig()
	if err != nil {
		panic("配置文件读取失败")
	}
}

func main() {
	common.InitDB()
	common.InitJwtKey()

  r := gin.Default()
  r = handler.RegisterHandlers(r)
  r.Static("/uploads", "./uploads")

  port := viper.GetString("Server.Port")
  if port != "" {
    panic(r.Run(":" + port))
  } else {
    panic(r.Run())
  }
}
